<?php
/**
 * 海报博主海报君推荐控件
 * bloggerrecommandcontroller.php
 * Create on 2015-04-18 11:47:45
 * Create by yuebin
 */
namespace haibao\cms\business\control\pc\channel\blog;

use haibao\cms\business\control\PublicController as PublicControllerBusiness;

class BloggerRecommandController extends \haibao\cms\business\control\pc\channel\ChannelController{
	
	public function __construct($updateTime = null,$controlId,$isPublish){
		parent::__construct($updateTime,$controlId,$isPublish);
	}
	
	
	/**
	 * 获取模版内容
	 * @param : String $content
	 */
	public function displayTemplateHtml(){
	
		$controlData = $this->getParameter(self::$CONTROL_DATA);
		$content = $this->getParameter(self::$CONTROL_CONTENT);
		$autoBlogs = $autoBlogger = $customBloggers = array();
		$countBlogList = 0;
		if($controlData['auto']){
			$autoBlogs = $this->getBlogCustomData($controlData['auto']);
			foreach($controlData['auto'] as $val){
				$resultData =json_decode($val['ParameterValue']);
				$autoBlogs[] = $resultData->bloggerId;
			}
		}
		$category = self::getBlogCategory();
		if($autoBlogs){
			$countBlogList = count($autoBlogs);
			$blogerIds = $autoBlogs;
			$blogIds = PublicControllerBusiness::geteBlogIdByUid($blogerIds);
		}else{
			$blogIds = PublicControllerBusiness::geteBlogIdByUid($autoBlogs);
		}
		if($blogIds){
			$customBlogArr = PublicControllerBusiness::getBlogListByBlogId($blogIds);
			if($customBlogArr){
				foreach($customBlogArr as $key=>$arr){
					$customBloggers[$arr['uid']] = array();
					$customBloggers[$arr['uid']]['uid'] = $arr['uid'];
					$customBloggers[$arr['uid']]['id'] = $arr['bloggerid'];
					$customBloggers[$arr['uid']]['uname'] = $arr['username'];
					if($arr['cateid']){
						$cateId = $arr['cateid'];
					}else{
						$cateId = 91;
					}
					$customBloggers[$arr['uid']]['cate_id'] = $cateId;
					$customBloggers[$arr['uid']]['catename'] = $category[$cateId]['name'];
					$customBloggers[$arr['uid']]['cateurl'] = $category[$cateId]['url'];
					$customBloggers[$arr['uid']]['usercenter'] = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_BOZHU).'/user/'.$arr['uid'].'/';;
					$customBloggers[$arr['uid']]['url'] = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_BOZHU).'/blog/'.$key.'.htm';
					$customBloggers[$arr['uid']]['subject'] = $arr['subject'];
					$customBloggers[$arr['uid']]['filename'] = $arr['filename'];
						
					array_push($autoBlogger,$arr['bloggerid']);
				}
			}
		}
		/**
		 * 先去根据Id取得值，如果取得到则下面只需要4-count($blogList)就可以了，而且Id要不等于自动数据的！
		 * blogList直接array_merge自动获取的数据，无论之前有没有数据，
		 */
		/* if(!isset($controlData['manual']['limit'])) $controlData['manual']['limit'] = 4;
		$bloggers = PublicControllerBusiness::getBloggerRecommand($controlData['manual']['limit']-$countBlogList,$autoBlogger);
		if($bloggers){
			$category = self::getBlogCategory();
			$uid = array_keys($bloggers);
			$blogList = PublicControllerBusiness::getBlogsByUid($uid);
			foreach($bloggers as $key=>$blogger){
				$bloggers[$key]['catename'] = $category[$blogger['cate_id']]['name'];
				$bloggers[$key]["cateurl"] =  $category[$blogger['cate_id']]['url'];
				$bloggers[$key]['usercenter'] = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_BOZHU).'/user/'.$blogger['uid'].'/';
				if(isset($blogList[$key])){
					$bloggers[$key]['url'] = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_BOZHU).'/blog/'.$blogList[$key]['blogid'].'.htm';
					$bloggers[$key]['subject'] = $blogList[$key]['subject'];
					$bloggers[$key]['filename'] = $blogList[$key]['filename'];
				}else{
					$bloggers[$key]['subject'] = $blogList[$key]['filename'] = $bloggers[$key]['url'] = '';
				}
			}
		}
		$bloggers = $customBloggers + $bloggers; */
		$this->assign('attentionType',\haibao\www\model\data\Favorite::ATTENTION_TYPE_BLOGGER);
		$this->assign('bloggers',json_decode(json_encode(array_values($customBloggers))));
		$path = $this->generateHtmlPath(__CLASS__);
		$this->generateHtml($path,$content);
		$content = $this->getHtml($path);
		$content = $this->replaceCDNLink($content);
		return $content;
	}
}